ultima prova decente
Category: Personal finance | Author: Anonymous | Published: January 20, 2025
ciao
} else {
// Utente anonimo
$email = $conn->real_escape_string($_POST['email'] ?? '');
if (empty($email)) {
$errorMessage = "Email is required for guest submissions.";
} else {
$sql = "INSERT INTO articles (title, user_id, email, category_id, slug, status)
VALUES ('$title', NULL, '$email', $category_id, '$slug', 'approved')";
if ($conn->query($sql)) {
$articleId = $conn->insert_id;
$contentSql = "INSERT INTO articles_content (article_id, body, link, anchor)
VALUES ($articleId, '$body', '$link', '$anchor')";
if ($conn->query($contentSql)) {
// Redirect dopo il successo
header("Location: submit.php?success=1");
exit;
} else {
$errorMessage = "Error saving article content: " . $conn->error;
}
} else {
$errorMessage = "Error submitting article: " . $conn->error;
}
}
}
}
}
}
}
// Funzioni helper per il generatore di slug
function generateUniqueSlug($conn, $title, $category_id) {
$slug = generateSlug($title);
$originalSlug = $slug;
$counter = 1;
while (true) {
$checkSlugQuery = "SELECT COUNT(*) as count FROM articles WHERE slug = '$slug' AND category_id = $category_id";
$result = $conn->query($checkSlugQuery);
if ($result && $result->fetch_assoc()['count'] == 0) {
break;
}
$slug = $originalSlug . '-' . $counter;
$counter++;
}
return $slug;
}
function generateSlug($string) {
$slug = strtolower($string);
$slug = preg_replace('/[^a-z0-9]+/i', '-', $slug);
$slug = trim($slug, '-');
return $slug;
}
?>